<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('运营指标配置') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <!--      <el-form-item :label="$t('排序')" prop="sort">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.sort"-->
      <!--          :placeholder="$t('排序')"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="queryHandle"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <el-form-item :label="$t('行业类型')" prop="industryType">
        <dict-select
          v-model="queryParams.industryType"
          dictionary="deal_industry_focus"
          :placeholder="$t('行业类型')"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t('搜索') }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('重置') }}</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['deal:indicator:edit']"
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="addHandle"
        >{{ $t('新增') }}</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="dealIndicatorPredictTypeList" border tooltip-effect="darkTable">
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('行业类型')" align="center" prop="industryType" :formatter="industryTypeFormat" />
      <!--      <el-table-column :label="$t('排序')" align="center" prop="sort" />-->
      <el-table-column :label="$t('备注')" align="center" show-overflow-tooltip prop="remark" />
      <el-table-column :label="$t('操作')" align="center" class-name="small-padding fixed-width" width="200">
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['deal:indicator:edit']"
            size="small"
            type="text"
            icon="el-icon-edit"
            @click="updateHandle(scope.row)"
          >{{ $t('修改') }}</el-button>
          <el-button
            v-hasPermi="['deal:indicator:edit']"
            size="small"
            type="text"
            icon="el-icon-edit"
            @click="editTemp(scope.row)"
          >{{ $t('数据维护') }}</el-button>
          <el-button
            v-hasPermi="['deal:indicator:remove']"
            size="small"
            type="text"
            icon="el-icon-delete"
            @click="deleteHandle(scope.row)"
          >{{ $t('删除') }}</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改盈利预测配置类型对话框 -->
    <el-dialog :title="$t(title)" :visible.sync="formOpen" :close-on-click-modal="false" :lock-scroll="false" :destroy-on-close="true" custom-class="dialogForm" append-to-body>
      <dealIndicatorPredictTypeForm ref="dealIndicatorPredictTypeForm" />
    </el-dialog>

    <!-- 数据维护督办事项模板对话框 -->
    <el-dialog v-if="indicatorOpen" :title="$t('数据维护')" :visible.sync="indicatorOpen" :close-on-click-modal="false" :lock-scroll="false" :destroy-on-close="true" custom-class="dialogForm" append-to-body>
      <dealIndicatorPredictList ref="dealIndicatorPredictList" :type-id="typeId" />
    </el-dialog>
  </div>
</template>

<script>
import { listDealIndicatorPredictType, delDealIndicatorPredictType } from '@/api/deal/indicator/dealIndicatorPredictType'
import dealIndicatorPredictTypeForm from './dealIndicatorPredictTypeForm.vue'
import dealIndicatorPredictList from './dealIndicatorPredictList.vue'
export default {
  components: {
    dealIndicatorPredictTypeForm,
    dealIndicatorPredictList
  },
  data() {
      return {
          // 遮罩层
          loading: true,
          // 总条数
          total: 0,
          // 盈利预测配置类型表格数据
          dealIndicatorPredictTypeList: [],
          // 弹出层标题
          title: '盈利预测配置类型',
          // 是否显示弹出层
          formOpen: false,
          indicatorOpen: false,
          // 类型ID
          typeId: '',
          // 聚焦行业 字典
          industryTypeOptions: [],
          // 查询参数
          queryParams: {
              industryType: undefined,
              sort: undefined,
              pageNum: 1,
              pageSize: 10
          },
          // 表单参数
          form: {},
          // 表单校验
          rules: {}
      }
  },
  created() {
      this.getList()
      this.getDicts('deal_industry_focus').then(response => {
        this.industryTypeOptions = response.data
      })
  },
  methods: {
    /** 查询盈利预测配置类型列表 */
    getList() {
        this.loading = true
        listDealIndicatorPredictType(this.queryParams).then(response => {
            this.dealIndicatorPredictTypeList = response.rows
            this.total = response.total
            this.loading = false
        }).catch(() => {
            this.loading = false
        })
    },
    // 聚焦行业字典翻译
    industryTypeFormat(row, column) {
      console.log(column)
      return this.selectDictLabel(this.industryTypeOptions, row.industryType)
    },

    // 表单重置
    reset() {
        this.form = {
            id: undefined,
            industryType: undefined,
            sort: undefined,
            remark: undefined,
            createBy: undefined,
            createTime: undefined,
            updateBy: undefined,
            updateTime: undefined,
            delFlag: undefined
        }
        this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
        this.queryParams.pageNum = 1
        this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
        this.resetForm('queryForm')
        this.queryHandle()
    },
    /** 新增按钮操作 */
    addHandle() {
        this.formOpen = true
        this.$nextTick(() => {
            this.$refs.dealIndicatorPredictTypeForm.init(null)
        })
    },
    /** 修改按钮操作 */
    updateHandle(row) {
        this.formOpen = true
        this.$nextTick(() => {
            // 调用form页面的 init 方法初始化数据
            this.$refs.dealIndicatorPredictTypeForm.init(row)
        })
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
        this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
        }).then(() => {
            return delDealIndicatorPredictType(row.id)
        }).then(() => {
            this.getList()
            this.msgSuccess(this.$t('删除成功'))
        }).catch(() => {
            this.loading = false
        })
    },
    editTemp(row) {
      this.indicatorOpen = true
      this.typeId = row.id
      this.$nextTick(() => {
        this.$refs.dealIndicatorPredictList.init(row)
      })
    }
  }
}
</script>
